package com.mo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.caucho.HessianServiceExporter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.mo.config.properties.HessianProperties;
import com.mo.config.properties.JwtProperties;
import com.mo.core.hessianProxyFactory.MoHessianProxyFactoryBean;
import com.mo.core.intercept.HessianInterceptor;
import com.mo.system.service.ISaveFileService;
import com.mo.tv.service.IZlSiteService;

/**
 * mo Web程序启动类
 *
 * @author chenxiaodong
 * @date 2018-05-21 9:43
 */
public class HessianServletInitializer extends WebMvcConfigurerAdapter {
	@Override
	  public void addInterceptors(InterceptorRegistry registry) {
	    registry.addInterceptor(new HessianInterceptor(jwtProperties))
	        .addPathPatterns("/hessian/**")
//	        .excludePathPatterns(FAVICON_URL)
	    ;
	  }

    @Autowired
	private JwtProperties jwtProperties;
	@Autowired
    private ISaveFileService saveFileService;
    @Bean(name = "/hessian/saveFileService")
    public HessianServiceExporter saveFileService() {
    	HessianServiceExporter exporter = new HessianServiceExporter();
      exporter.setService(saveFileService);
      exporter.setServiceInterface(ISaveFileService.class);
      return exporter;
    }
	@Autowired
	private HessianProperties hessianProperties;
	

	// ---------------------------------------------------------------------------------------------------------

	@Bean
	public MoHessianProxyFactoryBean zlSiteService() {
		MoHessianProxyFactoryBean factory = new MoHessianProxyFactoryBean( jwtProperties.getMd5Key(),jwtProperties.getSecret(),jwtProperties.getExpiration());
		factory.setServiceUrl(hessianProperties.getTvHessianUrl()
				+ "/hessian/zlSiteService");
		factory.setServiceInterface(IZlSiteService.class);
		return factory;
	}


}
